﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class GroupDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            if (Convert.ToString(Request.QueryString["GroupID"]) != null)
            {
                ListBind2();
                ImageListBind();
            }
            
        }

    }
    SqlConnection con = new SqlConnection();
    DataSet dsImages = new DataSet(); 
    string cnt = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
    public string GetSmallContents(string str, int chars)
    {
        if (str.Length > chars)
        {
            str = str.Substring(0, chars);
            str = str + "...";
        }
        return str;
    }
    private void ListBind2()
    {
        string qry = "select * from tbGroup where GroupID=" + Request.QueryString["GroupID"].ToString();
        SqlDataAdapter adp = new SqlDataAdapter(qry, cnt);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        lblGroupName.Text = Convert.ToString(ds.Tables[0].Rows[0]["GroupTitle"]);
        DataList2.DataSource = ds;
        DataList2.DataBind();
    }
    private void ImageListBind()
    {
        string qry = "select * from tbItems where GroupID=" + Request.QueryString["GroupID"].ToString();
        SqlDataAdapter adp = new SqlDataAdapter(qry, cnt);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        ImageList.DataSource = ds;
        ImageList.DataBind();
    }
   // select * from tbItems where GroupID=1
    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "GroupDetail")
        {
            Response.Redirect("GroupDetail.aspx?GroupID=" + e.CommandArgument);//         +"& NewsID="+aa);
        }
    }
    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptDetails1 = (Repeater)e.Item.FindControl("TopNews1");
            if (rptDetails1 != null)
            {
                string query = "select  * from tbItems where groupID=" + DataBinder.Eval(e.Item.DataItem, "GroupID").ToString();
                SqlDataAdapter adp = new SqlDataAdapter(query, cnt);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                //dsImages = SqlHelper.ExecuteDataset(con, CommandType.Text, query);
                if (ds != null)
                {
                    DataRow nRow = ds.Tables[0].NewRow();
                    nRow["ItemThumbPath"] = @"Resources/AddButton.png";
                    ds.Tables[0].Rows.Add(nRow);
                    ds.GetChanges();
                    //  gv.DataSource = ds.Tables[0]; 
                    rptDetails1.DataSource = ds;
                    rptDetails1.DataBind();
                }
            }

        }
    }
    protected void ImageList_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "thumbDetail")
        {
            Response.Redirect("ItemDetail.aspx?ItemID=" + e.CommandArgument + "&GroupID=" + Request.QueryString["GroupID"].ToString());
        }
    }
}